package com.czl.base.data.bean.tengyun

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import java.io.Serializable

/**
 * @author by xubin,
 * @date on 2022/2/9.
 * PS: Not easy to write code, please indicate.
 */
@Parcelize
class ProductBean(
    var productId: Int? = null,
    var productModel: String? = null,
    var productCode: String? = null,
    var productName: String? = null,
    var storehouseLocatName: String? = null,
    var inventoryResult: Int? = null,
    var shiftLocatOut: String? = null,
    var inventoryComment: String? = null,
    var inventoryPersonName: String? = null,
    var damageTypeStr: String? = null,
    var storehouseLocatId: Int? = null,
    var storehouseId: Int? = null,
    var sortId: Int? = null,
    var sortName: String? = null,
    var manufactureDate: String? = null,
    var inventoryPersonId: String? = null,
    var recordId: Int? = null,
    var applyType: Int? = null,
    var recordCode: String? = null,
    val userName: String? = null,
    var inStorehouseLocatId: Int? = null,
    var inventoryId: Int? = null,
    var inventoryProductId: Int? = null,
    var inventoryResultStr: String? = null,
    var price: String? = null,
    var supplier: String? = null,
    var unit: String? = null,
    var storehouseLocaName: String? = null,
    var classificationName: String? = null,
    var companyName: String? = null,
    var manufacturer: String? = null,
    var sortImg: String? = null,
    var isAssets: Boolean? = null,
    var moveProductId: Int? = null,
    var moveStorehouseLocatId: Int? = null,
    var isPasteCode: Boolean? = null,
) : Serializable, Parcelable {

    fun pasteCode(): Boolean {
        return if (isPasteCode == null) {
            false
        } else {
            isPasteCode!!
        }
    }

    fun isAllocateProduct(list: List<ProductBean>?): ProductBean? {
        if (list == null) {
            return null
        }
        for (productBean in list) {
            if (productBean.productId == productId) {
                return productBean
            }
        }
        return null
    }

    fun isRemand(): Boolean {
        return recordId != null && applyType != null
    }

    /**
     * 判断是否是待归还物品
     */
    fun isReturnProduct(list: List<ProductBean>?): Boolean {
        if (list == null) {
            return false
        }
        for (productBean in list) {
            if (productBean.productId == this.productId) {
                return true
            }
        }
        return false
    }

    fun isSortProduct(sortId: Int?): Boolean {
        return if (sortId == null) {
            false
        } else {
            sortId == this.sortId
        }
    }

    fun getDamageTypeStr(left: String, right: String): String {
        return if (damageTypeStr == null || damageTypeStr!!.isEmpty()) {
            ""
        } else left + damageTypeStr + right
    }

    fun getInventoryNum(list: List<ProductBean>?): Int {
        if (list == null) {
            return 0
        }
        var total = 0
        for (bean in list) {
            if (bean.inventoryResult != null) {
                total++
            }
        }
        return total
    }

    fun getProductPosition(list: List<ProductBean>?): Int {
        if (list == null) {
            return -1
        }
        for (i in list.indices) {
            val bean: ProductBean = list[i]
            if (bean.productId == productId) {
                return i
            }
        }
        return -1
    }

    companion object {

        //盘亏
        const val TYPE_DEFICIT = -1

        //正常
        const val TYPE_NORMAL = 0

        //盘盈
        const val TYPE_PANYING = 1

        //默认
        const val TYPE_DEFAULT = 2

        //未知状态
        const val TYPE_UNKNOWN = 3

        //盘亏
        const val RESULT_DEFICIT = -1

        //正常
        const val RESULT_NORMAL = 0

        //盘盈
        const val RESULT_PANYING = 1

        fun getInventoryNum(list: List<ProductBean>?): Int {
            if (list == null) {
                return 0
            }
            var total = 0
            for (bean in list) {
                if (bean.inventoryResult != null) {
                    total++
                }
            }
            return total
        }
    }

    fun getProductBean(list: List<ProductBean>?): ProductBean? {
        if (list == null) {
            return null
        }
        for (bean in list) {
            if (bean.productId == productId) {
                return bean
            }
        }
        return null
    }

}




